#include<bits/stdc++.h>
using namespace std;
string op,str;
inline bool check(string str){
	int n=str.size();
	int i=-1,num;
	for(int T=1;T<=4;T++){
		char ch=str[++i];
		if(!isdigit(ch)||ch=='0'&&isdigit(str[i+1])) return 0;
		num=0;
		for(;i<=n&&isdigit(str[i]);i++){
			num=num*10+str[i]-'0';
			if(num>255) break;
		}
		if(i>=n||num>255) return 0;
		if(T<=3&&str[i]!='.') return 0;
		if(T==4&&str[i]!=':') return 0;
	}
	char ch=str[++i];
	if(!isdigit(ch)||ch=='0'&&isdigit(str[i+1])) return 0;
	num=0;
	for(;i<=n&&isdigit(str[i]);i++){
		num=num*10+str[i]-'0';
		if(num>65535) break;
	}
	if(i<n||num>65535) return 0;
	return 1;
}
map<string,int>mp;
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	int T;
	cin>>T;
	for(int i=1;i<=T;i++){
		cin>>op>>str;
		if(!check(str)){
			puts("ERR");
			continue;
		}
		if(op[0]=='S'){
			if(mp.find(str)!=mp.end()){
				puts("FAIL");
			}else{
				mp[str]=i;
				puts("OK");
			}
		}else{
			if(mp.find(str)!=mp.end()){
				printf("%d\n",mp[str]);
			}else{
				puts("FAIL");
			}
		}
	}
}
